<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 查询条件 -->
        <content-block>
          <!-- 查询条件 -->
          <el-form :model="searchForm" label-width="110px" class="search-form" @submit.native.prevent>
            <el-row>
              <el-col :span="8">
                <el-form-item label="人员编号">
                  <person-rpc ref="personRpc" @personRpcCallBack="personRpcCallBack" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <personCustomCard ref="customCard" :label-obj="labelObj" />
        </content-block>

        <content-block label="账户类型">
          <!--          <el-form ref="aae140Form" :model="aae140Form" label-width="180px" class="search-form">-->
          <!--            <el-row :gutter="20">-->
          <!--              <el-col :span="16">-->
          <!--                <el-form-item label="险种类型" :rules="[ { required: true, message: '类型'},]">-->
          <!--                  <el-select v-model="aae140Form.aac062" placeholder="请选择"  style="width:80%" @change="changeAae140" >-->
          <!--                    <el-option v-for="item in dict.aac062" :key="item.id" :value="item.value" :label="item.label" />-->
          <!--                  </el-select>-->
          <!--                </el-form-item>-->
          <!--              </el-col>-->
          <!--            </el-row>-->
          <!--          </el-form>-->

          <el-table
            ref="table"
            v-loading="tableloding"
            :data="tableData4"
            size="small"
            border
            style="width: 100%;:height: 150"
            :header-cell-style="{background:'#f5f7fa', color:'#777'}"
          >
            <el-table-column type="index" width="50" align="center" header-align="center" />
            <el-table-column prop="aaz116" label="个人账户ID" align="center" header-align="center" />
            <el-table-column prop="aac062" label="类型" align="center" header-align="center">
              <template slot-scope="scope">
                {{ dict.label.aac062[scope.row.aac062] }}
              </template>
            </el-table-column>
            <el-table-column prop="aaz159" label="参保关系ID" align="center" header-align="center" />
            <el-table-column prop="aae206" label="建账年月" align="center" header-align="center" />
            <el-table-column prop="aae237" label="账户计息截止日期" align="center" header-align="center" />
            <el-table-column prop="aae238" label="本金" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae239" label="利息" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae240" label="账户金额" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae100" label="有效标识" align="center" header-align="center">
              <template slot-scope="scope">
                <template v-if="scope.row.aae100==='1'">
                  <el-tag
                    type="success"
                    disable-transitions
                  >有效</el-tag>
                </template>
                <template v-if="scope.row.aae100==='0'">
                  <el-tag
                    type="danger"
                    disable-transitions
                  >无效</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="个人账户打印"
              align="center"
              header-align="center"
              width="200"
            >
              <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-printer" size="mini" @click="printAccountForOne(scope.row)" />
              </template>
            </el-table-column>

          </el-table>

        </content-block>

        <content-block label="业务年度信息维护">
          <div style="margin-bottom: 15px;margin-left: 15px">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="addywnd">新增</el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="selectedRows.length == 0" @click="deleteywndbatch">删除</el-button>
          </div>
          <el-table
            ref="table"
            v-loading="tableloding"
            :data="tableData"
            size="small"
            border
            style="width: 100%;:height: 150"
            :header-cell-style="{background:'#f5f7fa', color:'#777'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="50" />
            <el-table-column prop="aaz159" label="参保关系ID" align="center" header-align="center" />
            <el-table-column prop="aae001" label="年度" align="center" header-align="center" />
            <el-table-column prop="bae095" label="月数" align="center" header-align="center" />

            <el-table-column
              fixed="right"
              label="操作"
              align="center"
              header-align="center"
              width="200"
            >
              <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="editywnd(scope.row)" />
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteywnd(scope.row)" />
              </template>
            </el-table-column>

          </el-table>

        </content-block>
        <content-block label="缴费明细信息修改">

          <el-form ref="mxForm" :model="mxForm" label-width="210px" class="search-form">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="对应费款所属期开始年月">
                  <el-date-picker
                    v-model="mxForm.beginyear"
                    type="month"
                    placeholder="选择月"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="对应费款所属期结束年月">
                  <el-date-picker
                    v-model="mxForm.endyear"
                    type="month"
                    placeholder="选择月"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" class="text-right" style="float: right">
                <el-form-item>
                  <el-button type="primary" @click="searchmx">查询</el-button>
                  <el-button @click="resetmx">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>

          </el-form>
          <div>
            <el-button type="primary" icon="el-icon-plus" size="mini" style="float: left;margin-left: 10px " @click="addmx">新增</el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="selectedRows2.length == 0" style="float: left;margin-left: 10px !important;" @click="deletemxbatch">删除</el-button>
            <el-button type="primary" icon="el-icon-download" size="mini" style="float: left;margin-left: 10px !important;" @click="exportTemplate">下载模版</el-button>

            <input
              ref="fileInput"
              type="file"
              accept=".xlsx,.xls"
              style="display: none"
              @change="handleFileChange"
            >

            <!-- 导入按钮，点击时触发 file input -->
            <el-button
              type="primary"
              icon="el-icon-upload"
              size="mini"
              :loading="loading"
              style="float: left;margin-left: 10px !important;"
              @click="triggerFileInput"
            >
              {{ loading ? '导入中...' : '导入Excel' }}
            </el-button>

          </div>

          <el-table ref="table2" v-loading="table2loding" :data="tableData2" size="small" border style="width: 100%;" height="550" :header-cell-style="{background:'#f5f7fa', color:'#777'}" @selection-change="handleSelectionChange2">
            <el-table-column type="selection" width="55" align="center" header-align="center" />
            <!--              <el-table-column prop="aaz648" label="养老保险人员实收明细ID" width="180"/>-->
            <!--              <el-table-column prop="aaz223" label="人员征缴明细ID" width="180"/>-->
            <!--              <el-table-column prop="aaz686" label="人员缴费ID" width="180"/>-->
            <el-table-column prop="aac001" label="人员编号" width="180" fixed="left" align="center" header-align="center" />
            <!--              <el-table-column prop="aaz159" label="人员参保关系ID" width="180"/>-->
            <!--              <el-table-column prop="aab001" label="单位编号" width="150" fixed="left"/>-->
            <!--              <el-table-column prop="aae140" label="险种类型" width="120" fixed="left"/>-->
            <el-table-column prop="aae003" label="对应费款所属期" width="120" fixed="left" align="center" header-align="center" />
            <el-table-column prop="aae002" label="费款所属期" width="120" align="center" header-align="center" />

            <el-table-column prop="aae820" label="类型" width="180" align="center" header-align="center">
              <template slot-scope="scope">
                <template v-if="scope.row.aae820==='1'">
                  <el-tag
                    type="success"
                    disable-transitions
                  >正常账户明细</el-tag>
                </template>
                <template v-if="scope.row.aae820==='9'">
                  <el-tag
                    type="warning"
                    disable-transitions
                  >改革前试点账户明细</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="aaa115" label="应缴类型" :formatter="formatter" width="180" align="center" header-align="center" />
            <el-table-column prop="aae793" label="地方应缴类型" :formatter="formatter" width="180" align="center" header-align="center" />
            <!--              <el-table-column prop="aae794" label="地方应缴类型名称" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aaa093" label="承担缴费主体类型" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aac066" label="参保身份" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aac313" label="地方参保身份码值" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aac314" label="地方参保身份名称" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae737" label="缴费资金来源" width="180" align="center" header-align="center"/>-->
            <el-table-column prop="aab019" label="单位类型" width="180" align="center" header-align="center" />
            <!--              <el-table-column prop="aab033" label="征缴方式" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae745" label="以个人身份参保人员缴费档次" width="180"/>-->
            <!--              <el-table-column prop="aac028" label="农民工标识" width="180" align="center" header-align="center"/>-->
            <el-table-column prop="aac040" label="工资" width="180" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aab121" label="单位缴费基数" width="180" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae180" label="人员缴费基数" width="180" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae795" label="记账基数" width="180" align="center" header-align="center" :formatter="formatMoney" />
            <el-table-column prop="aae871" label="缴费基数累计增加额" width="180" align="center" header-align="center" :formatter="formatMoney" />
            <!--              <el-table-column prop="aae828" label="利息征收标志" width="180"/>-->
            <!--              <el-table-column prop="aic380" label="利息截止年月" width="180"/>-->
            <!--              <el-table-column prop="aae834" label="滞纳金征收标志"width="180" />-->
            <!--              <el-table-column prop="aae845" label="滞纳金计算截止日期" width="180"/>-->
            <!--              <el-table-column prop="aae844" label="补缴规则" width="180"/>-->
            <el-table-column prop="aab191" label="到账日期" width="180" align="center" header-align="center" />
            <el-table-column label="实缴金额" header-align="center">
              <el-table-column prop="aae080" label="单位" width="180" align="center" header-align="center" :formatter="formatMoney" />
              <el-table-column prop="aae081" label="单位实缴划个人" width="180" align="center" header-align="center" :formatter="formatMoney" />
              <el-table-column prop="aae082" label="个人" width="180" align="center" header-align="center" :formatter="formatMoney" />
              <el-table-column prop="aae083" label="个人实缴划个人" width="180" align="center" header-align="center" :formatter="formatMoney" />
            </el-table-column>
            <!--              <el-table-column  label="实缴利息" header-align="center">-->
            <!--              <el-table-column prop="aae788" label="单位" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae789" label="单位实缴划入个人" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae790" label="个人" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae791" label="个人实缴划入个人" width="180" align="center" header-align="center"/>-->
            <!--              </el-table-column>-->
            <!--              <el-table-column  label="实缴金额利息其中本年利息" header-align="center">-->
            <!--              <el-table-column prop="aae840" label="单位" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae841" label="单位实缴划个人" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae842" label="个人" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae843" label="个人实缴划个人" width="180" align="center" header-align="center"/>-->
            <!--              </el-table-column>-->
            <!--              <el-table-column  label="滞纳金" header-align="center">-->
            <!--              <el-table-column prop="aae057" label="单位" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae888" label="个人" width="180" align="center" header-align="center"/>-->
            <!--              </el-table-column>-->
            <!--              <el-table-column prop="aae086" label="其他来源实缴金额" width="180" align="center" header-align="center"/>-->
            <!--              <el-table-column prop="aae741" label="数据来源" width="180" align="center" header-align="center"/>-->
            <el-table-column prop="aae202" label="缴费月数" width="180" align="center" header-align="center" />
            <el-table-column label="缴费比例" header-align="center">
              <el-table-column prop="aaa042" label="单位" width="180" align="center" header-align="center" />
              <el-table-column prop="aaa043" label="单位划入个人" width="180" align="center" header-align="center" />
              <el-table-column prop="aaa041" label="个人" width="180" align="center" header-align="center" />
              <el-table-column prop="aaa045" label="个人划入个人" width="180" align="center" header-align="center" />
            </el-table-column>
            <!--              <el-table-column prop="aaz616" label="核定批次号" width="180"/>-->
            <!--              <el-table-column prop="aaz615" label="核定流水号" width="180"/>-->
            <!--              <el-table-column prop="aae061" label="补退流水号" width="180"/>-->
            <!--              <el-table-column prop="aae108" label="参加单位结算标志" width="180"/>-->
            <!--              <el-table-column prop="aab301" label="转出地行政区划代码"width="180" />-->
            <!--              <el-table-column prop="aab299" label="转移参保地行政区划代码" width="180"/>-->
            <!--              <el-table-column prop="aae729" label="转入业务起息年月" width="180"/>-->
            <!--              <el-table-column prop="aae819" label="缴费备用字段1" width="180"/>-->
            <!--              <el-table-column prop="aae820" label="缴费备用字段2"width="180" />-->
            <!--              <el-table-column prop="aae796" label="双低系数（历史数据）" width="180"/>-->
            <!--              <el-table-column prop="aae797" label="固化社平工资（历史数据）" width="180"/>-->
            <!--              <el-table-column prop="aae798" label="基数比例（历史数据）" width="180"/>-->
            <!--              <el-table-column prop="aae799" label="固化指数" width="180"/>-->
            <!--              <el-table-column prop="aae800" label="账目类型" width="180"/>-->
            <!--              <el-table-column prop="aaz625" label="征集流水号" width="180" />-->
            <!--              <el-table-column prop="aae792" label="费用标志" width="180"/>-->
            <!--              <el-table-column prop="aae150" label="实收年月" width="180"/>-->
            <!--              <el-table-column prop="aae066" label="实收分配流水号" width="180"/>-->
            <!--              <el-table-column prop="aae748" label="退费年月" width="180"/>-->
            <!--              <el-table-column prop="aae822" label="退还账户滚存利息标志" width="180"/>-->
            <!--              <el-table-column prop="aaz631" label="退费批次号" width="180"/>-->
            <!--              <el-table-column prop="aaz650" label="退费流水号" width="180" />-->
            <el-table-column prop="aae013" label="备注" width="180" align="center" header-align="center" />
            <el-table-column prop="aae011" label="经办人" width="180" align="center" header-align="center" />
            <el-table-column prop="aae036" label="经办时间" width="180" align="center" header-align="center" />
            <el-table-column prop="aab359" label="参保地行政区划代码" width="180" align="center" header-align="center" />

            <el-table-column
              fixed="right"
              label="操作"
              align="center"
              header-align="center"
              width="200"
            >
              <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="editmx(scope.row)" />
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="deletemx(scope.row)" />
              </template>
            </el-table-column>

          </el-table>

          <!--分页组件-->
          <el-pagination

            :page-size.sync="page.size"
            :total="page.total"
            :current-page.sync="page.page"
            style="margin-top: 8px;float: right"
            layout="total, prev, pager, next, sizes"
            @size-change="sizeChangeHandler"
            @current-change="pageChangeHandler"
          />

        </content-block>

        <el-dialog :title="title_ac50a5" width="50%" :visible.sync="dialog_ac50a5">
          <el-form ref="ac50a5Form" :model="ac50a5Form" border size="small" label-width="100px">

            <el-col :span="12">
              <el-form-item v-show="false" label="参保关系ID" prop="aaz159">
                <el-input v-model="ac50a5Form.aaz159" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="年度" prop="aae001" :rules="[ { required: true, message: '年度不能为空'},]">
                <el-date-picker
                  v-model="ac50a5Form.aae001"
                  type="year"
                  placeholder="选择年"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="年度月数" prop="bae095" :rules="[ { required: true, },]">
                <el-input-number v-model="ac50a5Form.bae095" :min="1" :max="23" label="年度月数" />
              </el-form-item>
            </el-col>

          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="cancel_ywnd">取消</el-button>
            <el-button type="primary" @click="ok_ywnd">确认</el-button>
          </div>
        </el-dialog>

        <el-dialog title="新增实缴明细" width="75%" :visible.sync="dialog_ac08add">
          <el-tag type="danger" size="medium ">基数填写0，则默认按照个人账户划入比例（或定额）计算生成定额缴费明细！！！</el-tag>

          <content-block label="">

            <el-form ref="ac08addForm" :model="ac08addForm" border size="small" label-width="100px">
              <el-col :span="8">
                <el-form-item label="开始结束年月" prop="qh" label-width="180px" :rules="[ { required: true, message: '期号'},]">
                  <el-date-picker
                    v-model="ac08addForm.qh"
                    type="monthrange"
                    format="yyyy-MM"
                    range-separator="至"
                    start-placeholder="开始月份"
                    end-placeholder="结束月份"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="应缴类型" prop="aaa115" :rules="[ { required: true,message: '应缴类型'} ,]" label-width="180px">
                  <el-select v-model="ac08addForm.aaa115" placeholder="请选择" style="width:80%">
                    <el-option v-for="item in dict.aaa115.filter(m =>['10'].includes(m.value))" :key="item.id" :value="item.value" :label="item.label" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="类型" prop="aac062" :rules="[ { required: true,message: '类型'} ,]" label-width="180px">
                  <el-select v-model="ac08addForm.aac062" placeholder="请选择" style="width:80%">
                    <el-option v-for="item in dict.aac062" :key="item.id" :value="item.value" :label="item.label" />
                  </el-select>
                </el-form-item>

              </el-col>
              <el-col :span="8">
                <el-form-item label="缴费基数" prop="aae180" :rules="[ { required: true, message: '缴费基数'},]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aae180" size="medium" :precision="2" :step="0.1" min="0" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="社平工资" prop="aae797" :rules="[ { required: true,message: '社平工资'} ,]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aae797" size="medium" :precision="2" :step="0.1" min="0" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="单位缴费比例" prop="aaa042" :rules="[ { required: true,message: '单位缴费比例' },]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aaa042" size="medium" :precision="2" :step="0.1" min="0" max="1" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="单位划入比例" prop="aaa043" :rules="[ { required: true, message: '单位划入比例'},]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aaa043" size="medium" :precision="2" :step="0.1" min="0" max="1" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="个人划入比例(或定额)" prop="aaa045" :rules="[ { required: true, message: '个人划入比例'},]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aaa045" size="medium" :precision="2" :step="0.1" min="0" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="社平划入比例" prop="aae819" :rules="[ { required: true, message: '社平划入比例'},]" label-width="180px">
                  <el-input-number v-model="ac08addForm.aae819" size="medium" :precision="2" :step="0.1" min="0" max="1" />
                </el-form-item>
              </el-col>

              <el-button style="margin-right: 20px;float: right" @click="reloadDetail">重置条件</el-button>
              <el-button type="danger" style="margin-right: 20px;float: right" @click="DeleteDetail">批量删除</el-button>
              <el-button type="primary" style="margin-right: 20px;float: right" @click="addDetail">批量添加</el-button>
            </el-form>
          </content-block>

          <content-block label="明细信息">
            <el-table ref="table3" v-loading="table3loding" :data="tableData3" size="small" border style="width: 100%;" height="350" :header-cell-style="{background:'#f5f7fa', color:'#777'}" @selection-change="handleSelectionChange3">
              <el-table-column type="selection" width="55" />

              <el-table-column prop="aae003" label="对应费款所属期" width="100" fixed="left" align="center" header-align="center" />
              <el-table-column prop="aaa115" label="应缴类型" width="120" align="center" header-align="center" />
              <!--            <el-table-column prop="aae793" label="地方应缴类型" width="180"/>-->
              <!--            <el-table-column prop="aae794" label="地方应缴类型名称" width="180"/>-->
              <el-table-column prop="aae180" label="人员缴费基数" width="120" align="center" header-align="center" :formatter="formatMoney" />
              <!--            <el-table-column prop="aab191" label="到账日期" width="180"/>-->
              <el-table-column label="实缴金额" header-align="center"	align="center">
                <el-table-column prop="aae080" label="单位" width="120" align="center" header-align="center" :formatter="formatMoney" />
                <el-table-column prop="aae081" label="单位划入" width="120" align="center" header-align="center" :formatter="formatMoney" />
                <!--            <el-table-column prop="aae082" label="个人" width="180" />-->
                <el-table-column prop="aae086" label="社评" width="120" align="center" header-align="center" :formatter="formatMoney" />
                <el-table-column prop="aae083" label="个人划入" width="120" align="center" header-align="center" :formatter="formatMoney" />
              </el-table-column>
              <!--            <el-table-column  label="实缴利息" header-align="center"	 >-->
              <!--            <el-table-column prop="aae788" label="单位" width="180"/>-->
              <!--            <el-table-column prop="aae789" label="单位划入个人账户" width="180"/>-->
              <!--            <el-table-column prop="aae790" label="个人" width="180"/>-->
              <!--            <el-table-column prop="aae791" label="个人实缴划入个人账户" width="180"/>-->
              <!--            </el-table-column>-->
              <!--            <el-table-column  label="本年利息" header-align="center"	 >-->
              <!--            <el-table-column prop="aae840" label="单位" width="180"/>-->
              <!--            <el-table-column prop="aae841" label="单位划入个人账户" width="180"/>-->
              <!--            <el-table-column prop="aae842" label="个人" width="180"/>-->
              <!--            <el-table-column prop="aae843" label="个人实缴划入个人账户" width="180" />-->
              <!--            </el-table-column>-->
              <!--            <el-table-column  label="滞纳金" header-align="center"	 >-->
              <!--            <el-table-column prop="aae057" label="单位" width="180"/>-->
              <!--            <el-table-column prop="aae888" label="个人" width="180"/>-->
              <!--            </el-table-column>-->
              <!--            <el-table-column prop="aae086" label="其他来源实缴金额" width="180"/>-->
              <!--            <el-table-column prop="aae741" label="数据来源" width="180"/>-->
              <!--            <el-table-column prop="aae202" label="缴费月数" width="180"/>-->
              <el-table-column label="缴费比例" header-align="center"	align="center">
                <el-table-column prop="aaa042" label="单位" width="120" align="center" header-align="center" />
                <el-table-column prop="aaa043" label="单位划入" width="120" align="center" header-align="center" />
                <el-table-column prop="aae819" label="社评" width="120" align="center" header-align="center" />
                <el-table-column prop="aaa045" label="个人划入" width="120" align="center" header-align="center" />
              </el-table-column>
              <!--            <el-table-column prop="aae013" label="备注" width="180"/>-->
              <!--            <el-table-column prop="aae011" label="经办人" width="180"/>-->
              <!--            <el-table-column prop="aae036" label="经办时间" width="180"/>-->
              <!--            <el-table-column prop="aab359" label="参保地行政区划代码" width="180"/>-->

              <!--            <el-table-column-->
              <!--              fixed="right"-->
              <!--              label="操作"-->
              <!--              align="center"-->
              <!--              header-align="center"-->
              <!--              width="150">-->
              <!--              <template slot-scope="scope">-->
              <!--                <el-button  type="primary" icon="el-icon-edit" size="mini"  @click="editmx(scope.row)"/>-->
              <!--                <el-button   type="danger" icon="el-icon-delete" size="mini" @click="deletemx(scope.row)" />-->
              <!--              </template>-->
              <!--            </el-table-column>-->

            </el-table>
          </content-block>

          <div slot="footer" class="dialog-footer">
            <el-button type="info" @click="cancel_mx">取消</el-button>
            <el-button type="primary" @click="ok_mx">确认</el-button>
          </div>
        </el-dialog>

        <el-dialog title="编辑实缴明细" width="70%" :visible.sync="dialog_ac08edit">
          <el-tag type="danger" size="medium ">基数填写0，则默认按照个人账户划入比例（或定额）计算生成定额缴费明细！！！</el-tag>

          <el-form ref="ac08editForm" :model="ac08editForm" border size="small" label-width="100px">
            <el-col :span="12">
              <el-form-item v-show="false" label="养老保险人员实收明细ID" prop="aaz648">
                <el-input v-model="ac08editForm.aaz648" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="应缴类型" prop="aaa115" :rules="[ { required: true,message: '应缴类型'} ,]" label-width="180px">
                <el-select v-model="ac08editForm.aaa115" placeholder="请选择" style="width:80%">
                  <el-option v-for="item in dict.aaa115.filter(m =>['10'].includes(m.value))" :key="item.id" :value="item.value" :label="item.label" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="缴费基数" prop="aae180" :rules="[ { required: true, message: '缴费基数'},]" label-width="180px">
                <el-input-number v-model="ac08editForm.aae180" size="medium" :precision="2" :step="0.1" min="0" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="单位缴费比例" prop="aaa042" :rules="[ { required: true,message: '单位缴费比例' },]" label-width="180px">
                <el-input-number v-model="ac08editForm.aaa042" size="medium" :precision="2" :step="0.1" min="0" max="100" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="单位划入比例" prop="aaa043" :rules="[ { required: true, message: '单位划入比例'},]" label-width="180px">
                <el-input-number v-model="ac08editForm.aaa043" size="medium" :precision="2" :step="0.1" min="0" max="100" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="个人划入比例（或定额）" prop="aaa045" :rules="[ { required: true, message: '个人划入比例'},]" label-width="180px">
                <el-input-number v-model="ac08editForm.aaa045" size="medium" :precision="2" :step="0.1" min="0" max="100" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="社评划入比例" prop="aae819" :rules="[ { required: true, message: '社评划入比例'},]" label-width="180px">
                <el-input-number v-model="ac08editForm.aae819" size="medium" :precision="2" :step="0.1" min="0" max="100" />
              </el-form-item>
            </el-col>

          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="info" @click="cancel_mx">取消</el-button>
            <el-button type="primary" @click="ok_editmx">确认</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
    <bottom-fixed>
      <div>
        <el-button type="primary" style="margin-right: 50px" @click="computerAccount">个人账户重汇</el-button>
        <!--        <el-button type="primary" style="margin-right: 50px" @click="printAccount">个人账户打印</el-button>-->
      </div>
    </bottom-fixed>
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'

import PersonRpc from '@/views/ynsb_comm/comm/module/personRpc.vue'
import crudBasicAc01 from '@/views/ynsb_comm/ac01/basicAc01'
import contentBlock from '@/components/labers/contentBlock'
import bottomFixed from '@/components/labers/bottomFixed'
import apiac08 from '@/views/ynsb_comm/ac08/js/accountAc08'
import apiac50a5 from '@/views/ynsb_comm/ac08/js/accountAc50a5'
import crudBasicAc50 from '@/views/ynsb_comm/ac50/basicAc50'
import PersonCustomCard from '@/views/ynsb_comm/comm/module/personCustomCard.vue'
import { downloadFile } from '@/utils'
import { Loading } from 'element-ui'

const defaultForm = { aaz153: null, aaa032: null, aaa030: null, aaa031: null, aae013: null, aae011: null, aae036: null, aae041: null, aae042: null, aab359: null }
const labelObj = { aac002: '社会保障号码', aac003: '姓名', aac001: '个人编号', aac006: '出生日期', aac004: '性别' }
export default {
  name: 'TransferOut',
  components: { PersonCustomCard, PersonRpc, contentBlock, bottomFixed },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'api', url: 'api/accountAa08', idField: 'aaz153', sort: 'aaz153,desc', crudMethod: { ...apiac08 }})
  },
  // 数据字典
  dicts: ['aae140', 'aae793', 'aaa115', 'aac062'],
  data() {
    return {
      cardPerson: [],
      labelObj,
      aaz159: '',
      aac001: '',
      aae140: '',
      aab001: '',
      aac062: '',

      searchForm: {
        aac001: '', // 人员编号
        aac003: '' // 姓名
      },

      aae140Form: {
        aac062: '' // 养老保险转移制度方向
      },

      ac50a5Form: {
        aaz159: '',
        aae001: '',
        bae095: ''
      },
      mxForm: {
        beginyear: null,
        endyear: null
      },

      ac08addForm: {
        qh: '',
        aae180: '',
        aaa115: '',
        aac062: '',
        aae797: '',
        aaa043: '',
        aaa042: '',
        aaa045: '',
        aae819: ''
      },

      ac08editForm: {
        aaz648: '',
        aaz223: '',
        aaz686: '',
        aac001: '',
        aaz159: '',
        aab001: '',
        aae140: '',
        aae002: '',
        aae003: '',
        aaa115: '',
        aae793: '',
        aae794: '',
        aaa093: '',
        aac066: '',
        aac313: '',
        aac314: '',
        aae737: '',
        aab019: '',
        aab033: '',
        aae745: '',
        aac028: '',
        aac040: '',
        aab121: '',
        aae180: '',
        aae795: '',
        aae871: '',
        aae828: '',
        aic380: '',
        aae834: '',
        aae845: '',
        aae844: '',
        aab191: '',
        aae080: '',
        aae081: '',
        aae082: '',
        aae083: '',
        aae788: '',
        aae789: '',
        aae790: '',
        aae791: '',
        aae840: '',
        aae841: '',
        aae842: '',
        aae843: '',
        aae057: '',
        aae888: '',
        aae086: '',
        aae741: '',
        aae202: '',
        aaa042: '',
        aaa043: '',
        aaa041: '',
        aaa045: '',
        aaz616: '',
        aaz615: '',
        aae061: '',
        aae108: '',
        aab301: '',
        aab299: '',
        aae729: '',
        aae819: '',
        aae820: '',
        aae796: '',
        aae797: '',
        aae798: '',
        aae799: '',
        aae800: '',
        aaz625: '',
        aae792: '',
        aae150: '',
        aae066: '',
        aae748: '',
        aae822: '',
        aaz631: '',
        aaz650: '',
        aae013: '',
        aae011: '',
        aae036: '',
        aab359: ''
      },

      file: null,
      loading: false,

      tableData: [], // 基本养老信息表明细信息
      tableData2: [], // 账户明细信息
      tableData3: [], // 账户新增明细信息
      tableData4: [], // 账户信息
      show_tab1: true,
      show_tab2: false,
      show_tab3: false,
      title_ac50a5: '',
      dialog_ac50a5: false,
      dialog_ac08add: false,
      dialog_ac08edit: false,

      selectedRows: [], // 存储选中的行数据
      selectedRows2: [], // 存储选中的行数据
      selectedRows3: [], // 存储选中的行数据
      page: {
        // 页码
        page: 0,
        // 每页数据条数
        size: 10,
        // 总数
        total: 0
      }

    }
  },
  computed: {
    filteredOptions() {
      const filtered = this.dict.filter(item => {
        const excluded = [140, 180] // 要过滤掉的值的数组
        return !excluded.includes(item.value)
      })
      return filtered
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },

    personRpcCallBack(item) {
      this.aac001 = item.aac001
      this.aac003 = item.aac003
      this.searchForm = {
        aac001: item.aac001,
        aac003: item.aac003
      }

      // 查询账户信息
      crudBasicAc50.getAc02({ ...this.searchForm }).then(res => {
        console.log(res, '险种信息')
        this.$refs.customCard.fnSetContentArray(item.aac001, item.aac003, item, this.labelObj, res)
      })

      this.search()
    },
    search() {
      // 假设查询的数据
      if (this.searchForm.aac001 !== '' && this.searchForm.aac001 !== null) {
        crudBasicAc01.getAc01Ac02({ ...this.searchForm }).then(res => {
          this.cardPerson = res

          const filteredValues = this.cardPerson.filter(item => item.aae140 === '120' && item.aac008 === '1')
          if (filteredValues.length === 0) {
            this.$message('未查询到该人员当前险种有效参保关系')
            return
          }
          this.aaz159 = filteredValues[0].aaz159
          this.aac001 = filteredValues[0].aac001
          this.aae140 = '120'
          this.aab001 = filteredValues[0].aab001
          this.getac50a5()
          this.getac50()
        })
      }
    },

    formatter(row, column, cellValue) {
      // 根据 aae140 的值进行转码
      const key = column.property
      const data = this.dict[key]
      console.log(data, 'data')
      const dataList = data.filter(item => item.value === cellValue)
      if (dataList !== null && dataList !== [] && dataList !== undefined) {
        return dataList[0].label
      }
    },

    changeAae140(val) {
      const filteredValues = this.cardPerson.filter(item => item.aae140 === '120' && item.aac008 === '1')
      if (filteredValues.length === 0) {
        this.$message('未查询到该人员当前险种有效参保关系')
        return
      }
      this.aaz159 = filteredValues[0].aaz159
      this.aac001 = filteredValues[0].aac001
      this.aae140 = '120'
      this.aab001 = filteredValues[0].aab001
      this.aac062 = val
      this.getac50a5()

      this.getac50()
    },

    /**
     * 下载模版
     */
    exportTemplate() {
      apiac08.downloadTemplate().then(response => {
        console.log(response)
        downloadFile(response, '个人缴费明细录入模版', 'xlsx')
        this.$message.success('模板下载成功')
      }).catch(err => {
        this.$message.error('模板下载失败')
        console.error(err)
      })
    },

    // 触发文件选择
    triggerFileInput() {
      this.$refs.fileInput.click() // 模拟点击 input[type=file]
    },

    // 文件选择回调（选择后自动上传）
    async handleFileChange(event) {
      const file = event.target.files[0]
      if (!file) return
      debugger
      const formData = new FormData()
      formData.append('file', file)
      formData.append('aac001', this.aac001)
      formData.append('aaz159', this.aaz159)
      formData.append('aab001', this.aab001)

      this.loading = true
      try {
        const res = await apiac08.importExcel(formData)
        this.$message.success(`导入成功，共 ${res.total} 条数据！`)
      } catch (error) {
        console.error('导入错误详情:', error)

        // 使用解构赋值
        const response = error.response || {}
        const data = response.data || {}
        const errorMsg = data

        this.$message.error('导入失败：' + errorMsg)
      } finally {
        this.loading = false
        event.target.value = ''
      }
    },

    // 监听选中变化
    handleSelectionChange(val) {
      this.selectedRows = val
    },
    // 监听选中变化
    handleSelectionChange2(val) {
      this.selectedRows2 = val
    },
    // 监听选中变化
    handleSelectionChange3(val) {
      this.selectedRows3 = val
    },

    getac50a5() {
      this.tableloding = true
      apiac50a5.get({ aaz159: this.aaz159 }).then(res => {
        console.log(res)
        this.tableData = res
        this.tableloding = false
      })
    },

    getac50() {
      apiac08.getAc50all({ aac001: this.aac001, aaz159: this.aaz159, aac062: this.aac062 }).then(res => {
        console.log('ac50:' + res)
        this.tableData4 = res.ac50
      })
    },

    // 新增业务年度
    addywnd() {
      this.ac50a5Form.aaz159 = this.aaz159
      this.title_ac50a5 = '新增业务年度信息'
      this.dialog_ac50a5 = true
    },
    // 编辑业务年度
    editywnd(row) {
      this.title_ac50a5 = '编辑业务年度信息'
      this.dialog_ac50a5 = true
      this.ac50a5Form = row
      this.ac50a5Form.aae001 = row.aae001.toString()
    },
    // 取消保存
    cancel_ywnd() {
      this.dialog_ac50a5 = false
    },
    // 保存
    ok_ywnd() {
      // 蒙层
      const loadingInstance = Loading.service({
        fullscreen: true, // 是否全屏
        text: '保存中...', // 加载文本
        background: 'rgba(0, 0, 0, 0.7)' // 蒙层背景颜色
      })
      if (this.title_ac50a5 === '新增业务年度信息') {
        this.$refs.ac50a5Form.validate(valid => {
          if (valid) {
            console.log(this.ac50a5Form)
            const date = new Date(this.ac50a5Form.aae001)
            const year = date.getFullYear() // 提取年份
            const data = this.ac50a5Form
            data.aae001 = year

            apiac50a5.add(JSON.stringify(data)).then(res => {
              this.$notify({
                title: '保存成功',
                type: 'success'
              })
              loadingInstance.close()
              this.getac50a5()
            })
          }
        })
      } else {
        this.$refs.ac50a5Form.validate(valid => {
          if (valid) {
            console.log(this.ac50a5Form)
            const date = this.ac50a5Form
            apiac50a5.edit(date).then(res => {
              this.$notify({
                title: '保存成功',
                type: 'success'
              })
              loadingInstance.close()
              this.getac50a5()
            })
          }
        })
      }

      this.dialog_ac50a5 = false
    },

    deleteywnd(row) {
      this.selectedRows = row
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteac50a5()
      }).catch(() => {

      })
    },

    deleteywndbatch() {
      if (this.selectedRows.length === 0) {
        this.$message('请选择要删除的数据')
        return
      }

      this.$confirm('是否确认删除选中数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteac50a5()
      }).catch(() => {

      })
    },

    deleteac50a5() {
      apiac50a5.del(JSON.stringify(this.selectedRows)).then(res => {
        this.$notify({
          title: '删除成功',
          type: 'success'
        })
        this.getac50a5()
      })
    },

    // 查询缴费明细信息
    searchmx() {
      debugger
      this.table2loding = true
      if (this.aaz159 == null || this.aaz159.length <= 0) {
        this.$message('参保关系ID不能为空')
        return
      }

      this.$refs.mxForm.validate(valid => {
        if (valid) {
          const data = {}
          if (this.mxForm.beginyear != null) {
            const beginyear = this.formatDateToYearMonth(this.mxForm.beginyear)
            data.aae003start = beginyear
          }
          if (this.mxForm.endyear != null) {
            const endyear = this.formatDateToYearMonth(this.mxForm.endyear)
            data.aae003end = endyear
          }
          data.aaz159 = this.aaz159
          data.page = this.page.page - 1
          data.size = this.page.size
          apiac08.get(JSON.stringify(data)).then(res => {
            this.tableData2 = res.content
            this.page.total = res.totalElements
            this.table2loding = false
          })
        }
      })
    },
    resetmx() {
      this.$refs.mxForm.resetFields()
    },

    // 新增缴费明细弹窗
    addmx() {
      this.dialog_ac08add = true
      this.tableData3 = []
      this.ac08addForm = {}
    },
    // 编辑缴费明细
    editmx(row) {
      debugger
      this.dialog_ac08edit = true
      this.ac08editForm = row
    },

    // 新增明细信息
    addDetail() {
      this.$refs.ac08addForm.validate(valid => {
        if (valid) {
          const retireFormdata = {}
          // 获取form的值
          const aae180 = this.ac08addForm.aae180
          const aaa043 = this.ac08addForm.aaa043
          const aaa042 = this.ac08addForm.aaa042
          const aaa045 = this.ac08addForm.aaa045
          const aae819 = this.ac08addForm.aae819
          const aae797 = this.ac08addForm.aae797
          const aac062 = this.ac08addForm.aac062
          const aae041 = this.formatDateToYearMonth(this.ac08addForm.qh[0])
          const aae042 = this.formatDateToYearMonth(this.ac08addForm.qh[1])
          const arr = []
          // 循环赋值
          for (let i = aae041; i <= aae042; i = this.addMonth(i, 1)) {
            retireFormdata.aae820 = aac062
            retireFormdata.aae003 = i
            retireFormdata.aaa115 = this.ac08addForm.aaa115 // 应缴类型
            retireFormdata.aab191 = i + '01' // 到账日期
            retireFormdata.aae202 = '1' // 缴费月数（隐藏）
            retireFormdata.aae180 = aae180
            retireFormdata.aac001 = this.aac001
            retireFormdata.aae140 = this.aae140
            retireFormdata.aab001 = this.aab001
            retireFormdata.aaz159 = this.aaz159

            if (aae180 === 0 || aae180 === '0') {
              retireFormdata.aaa042 = 0
              retireFormdata.aaa043 = 0
              retireFormdata.aaa045 = aaa045
              retireFormdata.aae819 = 0

              retireFormdata.aae080 = 0
              retireFormdata.aae081 = 0
              retireFormdata.aae083 = aaa045
              retireFormdata.aae086 = 0
            } else {
              retireFormdata.aaa042 = aaa042
              retireFormdata.aaa043 = aaa043
              retireFormdata.aaa045 = aaa045
              retireFormdata.aae819 = aae819

              retireFormdata.aae080 = aae180 * aaa042
              retireFormdata.aae081 = aae180 * aaa043
              retireFormdata.aae083 = aae180 * aaa045
              retireFormdata.aae086 = aae797 * aae819
            }

            // }
            arr.push({ ...retireFormdata })
          }

          this.tableData3 = arr
        }
      })
    },

    // 删除明细信息
    DeleteDetail() {
      if (this.selectedRows3.length === 0) {
        this.$message('请选择要删除的数据')
        return
      }

      const arr = this.selectedRows3
      const newArr = this.tableData3.filter(item => !arr.some(item1 => item1.aae003 === item.aae003 && item1.key === item.key))
      this.tableData3 = newArr
    },

    // 重置查询
    reloadDetail() {
      this.ac08addForm = {}
    },

    // 取消保存明细
    cancel_mx() {
      this.dialog_ac08add = false
      this.dialog_ac08edit = false
    },

    // 保存明细信息新增
    ok_mx() {
      if (this.tableData3.length === 0) {
        this.$message('请先添加需要保存的数据')
        return
      }

      const loadingInstance = Loading.service({
        fullscreen: true, // 是否全屏
        text: '保存中...', // 加载文本
        background: 'rgba(0, 0, 0, 0.7)' // 蒙层背景颜色
      })

      apiac08.add(JSON.stringify(this.tableData3)).then(res => {
        this.$notify({
          title: '保存成功',
          type: 'success'
        })
        loadingInstance.close()
        this.searchmx()
      })

      this.dialog_ac08add = false
    },

    ok_editmx() {
      this.$refs.ac08editForm.validate(valid => {
        if (valid) {
          const date = this.ac08editForm
          apiac08.edit(date).then(res => {
            this.$notify({
              title: '保存成功',
              type: 'success'
            })
            this.searchmx()
          })
        }
      })
      this.dialog_ac08edit = false
    },

    deletemx(row) {
      this.selectedRows2 = row
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteac08()
      }).catch(() => {

      })
    },

    deletemxbatch() {
      if (this.selectedRows2.length === 0) {
        this.$message('请选择要删除的数据')
        return
      }

      this.$confirm('是否确认删除选中数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteac08()
      }).catch(() => {

      })
    },

    deleteac08() {
      apiac08.del(JSON.stringify(this.selectedRows2)).then(res => {
        this.$notify({
          title: '删除成功',
          type: 'success'
        })
        this.searchmx()
      })
    },

    // 当前页改变
    pageChangeHandler(e) {
      this.page.page = e
      this.searchmx()
    },
    // 每页条数改变
    sizeChangeHandler(e) {
      this.page.size = e
      this.page.page = 1
      this.searchmx()
    },
    // 预防删除第二页最后一条数据时，或者多选删除第二页的数据时，页码错误导致请求无数据
    dleChangePage(size) {
      if (this.tableData2.length === size && this.page.page !== 1) {
        this.page.page -= 1
      }
    },

    // 个人账户重汇
    computerAccount() {
      // 蒙层
      const loadingInstance = Loading.service({
        fullscreen: true, // 是否全屏
        text: '计算中...', // 加载文本
        background: 'rgba(0, 0, 0, 0.7)' // 蒙层背景颜色
      })
      apiac08.computerAccount({ aaz159: this.aaz159, aac001: this.aac001, aae140: this.aae140 }).then(res => {
        this.$notify({
          title: '重汇成功',
          type: 'success'
        })

        this.getac50a5()
        this.getac50()
        loadingInstance.close()
        // eslint-disable-next-line handle-callback-err
      }).catch(err => {
        loadingInstance.close()
      })
    },
    // 个人账户打印
    printAccount() {
      window.open('http://localhost:8085/jmreport/view/1093757605187809280?token=123456&tenantId=3&aaz159=' + this.aaz159, '_blank')
    },
    // 个人账户打印
    printAccountForOne(row) {
      window.open('http://localhost:8085/jmreport/view/1094780585487863808?token=123456&tenantId=3&aaz159=' + this.aaz159 + '&aac062=' + row.aac062, '_blank')
    },

    // 时间格式化
    formatDateToYearMonth(dateStr) {
      const date = new Date(dateStr)
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2) // 确保两位数月份
      return `${year}${month}`
    },

    formatMoney(row, column, cellValue) {
      const value = (cellValue != null) ? `￥${(Number(cellValue).toFixed(2) + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,')}` : '--'
      // 判断金额并设置样式
      if (cellValue < 0) {
        return <span style='color: red; font-weight: bold;'>{value}</span>
      } else if (cellValue >= 0) {
        return <span style='color: green; font-weight: bold;'>{value}</span>
      }
    },

    // 期号加减
    addMonth(yyyymm, mm) {
      if (yyyymm) {
        yyyymm = parseInt(yyyymm)
        let nmm = yyyymm % 100
        let nyy = parseInt(yyyymm / 100)
        nmm += mm
        nyy += Math.ceil(nmm / 12) - 1
        nmm = (nmm % 12) === 0 ? 12 : (nmm % 12)
        return nyy * 100 + nmm
      } else {
        return 0
      }
    }

  }
}
</script>

<style scoped>

</style>

